<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #box{
            width: 550px;
            border: 2px solid black;
            padding: 10px;
        }
        img{
            border: 2px solid red;
            opacity:0.5;
        }
    </style>
</head>
<body>
    <div id="box">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
        <img src="./1.jpg" alt="">
    </div>
</body>
</html>
<script>
    var img = document.querySelectorAll('img')
    for(var i = 0 ;i<img.length ; i++){
        img[i].onmouseover = function(){
            this.style.cssText = 'opacity:1;'
        }
        img[i].onmouseout = function(){
            this.style.cssText = 'opacity:0.5;'
        }
    }
</script>